package org.yufan.core.conveter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zxd on 2019/3/1
 **/
public class DateConverter implements Converter<String,Date> {

    @Override
    public Date convert(String source) {

        try {
            if (StringUtils.isEmpty(source)) {
                return null;
            }

            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return df.parse(source);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

}
